<template>
  <div id="app">
    <div class="box">
      <label for="name">姓名：</label>
      <input type="text" id="name" v-model="msg">
    </div>
    <div class="box">
      <label for="age">年龄：</label>
      <input type="number" id="age" v-model="age">
    </div>
    <div class="box">
      <label for="height">身高：</label>
      <input type="text" id="height" v-model="height">(米)
    </div>
    <div class="box">
      <label for="weight">体重：</label>
      <input type="text" id="weight" v-model="weight">(公斤)
    </div>
    <div class="box">
      <label for="history">病史：</label>
      <input type="text" id="history" v-model="history">
    </div>
    <button class="btn" @click="getResult">诊断</button>
    <p class="result">{{ result }}</p>
  </div>
</template>

<script>
export default {
  name: 'app',
  data() {
    return {
      msg: '',
      age: '',
      height: '',
      weight: '',
      history: '',
      result: ''
    }
  },
  methods: {
    getResult() {
      if (this.msg && this.age && this.height && this.weight && this.history) {
        const heightNum = parseFloat(this.height);
        const weightNum = parseFloat(this.weight);
        if (isNaN(heightNum) || isNaN(weightNum)) {
          this.result = '请输入有效的身高和体重（数字）';
          return;
        }
        if (heightNum < 0.5 || heightNum > 2.5) {
          this.result = '输入的身高不在正常范围（0.5 米到 2.5 米）';
          return;
        }
        if (weightNum < 20 || weightNum > 200) {
          this.result = '输入的体重不在正常范围（20 公斤到 200 公斤）';
          return;
        }
        let bmi = weightNum / (heightNum * heightNum);
        if (bmi <= 18.5) {
          this.result = `患者 ${this.msg} 的诊断结果：体重过轻`;
        } else if (bmi > 18.5 && bmi <= 24.9) {
          this.result = `患者 ${this.msg} 的诊断结果：正常`;
        } else if (bmi > 24.9 && bmi <= 29.9) {
          this.result = `患者 ${this.msg} 的诊断结果：体重过重`;
        } else {
          this.result = `患者 ${this.msg} 的诊断结果：肥胖`;
        }
      }
    }
  }
}
</script>

<style>
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-color: #f0f0f0;
  font-family: Arial, sans-serif;
}
.box {
  display: flex;
  flex-direction: column;
  margin-bottom: 15px;
  width: 300px;
}
label {
  font-size: 14px;
  color: #333;
  margin-bottom: 5px;
}
input {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}
input:focus {
  outline: none;
  border-color: #66afe9;
  box-shadow: 0 0 5px #66afe9;
}
.btn {
  padding: 10px 20px;
  background-color: #007BFF;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  margin-top: 15px;
}
.btn:hover {
  background-color: #0056b3;
}
.result {
  font-size: 16px;
  color: #007BFF;
  margin-top: 20px;
}
</style>